//对于axios进行二次封装
import axios from "axios";
import nProgress from "nprogress";
import 'nprogress/nprogress.css'


//1.创建axios实例
const requests = axios.create({
    baseURL: "/api",
    timeout: 5000,
});

//请求拦截器
requests.interceptors.request.use((config) => {
    nProgress.start();
    return config;
})

//响应拦截器
requests.interceptors.response.use((response) => {
    nProgress.done();
    //成功回调
    return response.data;
// eslint-disable-next-line no-unused-vars
}, (error) => {
    //响应失败的回调
    return Promise.reject(new Error("fail"));
})

//对外暴露
export default requests;
